package com.souche.employment.dto;

import com.souche.employment.domain.EmployeeDO;
import com.souche.employment.es.domain.PersonSearchDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * EmployeeDto created at 2017/9/22 下午7:34
 * Ray [email:rayinhangzhou@126.com]
 * Revision History
 * Date            Programmer                   Notes
 * ----------------------------------------------------------
 **/

@Data
public class EmployeeDto implements Serializable {

    private String id;
    private String name;
    private String gender;
    private Integer age;
    private Integer workAge;
    private String phone;
    private String mail;
    private String pipe;
    private String referee;
    private String sender;
    private String tips;
    private String jobId;
    private String jobName;
    private String dep1;
    private String dep2;
    private String inviteStatus;
    private String interviewStatus;
    private Date interviewTime;
    private String interviewType;
    private String interviewer0;
    private String interviewer1;
    private String interviewer2;
    private String file;
    private String creator;
    private Date dateCreate;
    private Date dateUpdate;

    @ApiModelProperty("入职时间")
    private Date dateEntry;
    @ApiModelProperty("处理状态")
    private String dealStatus;

    public EmployeeDto() {

    }

    public EmployeeDto(EmployeeDO employeeDO) {
        BeanUtils.copyProperties(employeeDO, this);
        this.dealStatus = getDealStatus(this.interviewStatus);
        this.dateEntry = null;
    }

    public EmployeeDto(PersonSearchDO personSearchDO) {
        this.id = personSearchDO.getId();
        this.name = personSearchDO.getName();
        this.phone = personSearchDO.getPhone();
        this.jobId = personSearchDO.getJobId();
        this.jobName = personSearchDO.getJobName();
        this.dep1 = personSearchDO.getDep1();
        this.dep2 = personSearchDO.getDep2();
        this.tips = personSearchDO.getTip();
        this.inviteStatus = personSearchDO.getInviteStatus();
        this.interviewStatus = personSearchDO.getInterviewStatus();
        this.dealStatus = getDealStatus(this.interviewStatus);
        this.dateEntry = personSearchDO.getDateEntry() == 0 ? null : new Date(personSearchDO.getDateEntry());
        this.dateCreate = new Date(personSearchDO.getDateCreate());
    }


    private String getDealStatus(String interviewStatus) {
        if ("淘汰,储备,已入职,已离职,录用".contains(interviewStatus)) {
            return "done";
        }
        return "doing";
    }
}
